package cn.jorian.framework.service.impl;

import cn.jorian.framework.bean.DataBean;
import cn.jorian.framework.bean.GoodsBean;
import cn.jorian.framework.bean.ResponseResult;
import cn.jorian.framework.net.NetManager;
import cn.jorian.framework.service.ApiBaseService;
import cn.jorian.framework.service.IGoodsService;
import cn.jorian.framework.util.ParamUtil;
import org.springframework.stereotype.Service;
import retrofit2.Response;

import java.io.IOException;

@Service
public class GoodsServiceImpl implements IGoodsService {

    @Override
    public ResponseResult goods() {
        GoodsBean goodsBean = new GoodsBean();
        goodsBean.setOwnerCode("19940");
        goodsBean.setOwnerOgoodsCode("1001");

        //data
        DataBean<GoodsBean> dataBean = new DataBean<>();
        dataBean.setInterfaceNbr("goods");
        dataBean.addRecord(goodsBean);

        try {
            //同步post请求
            Response<ResponseResult> response = NetManager.newInstance().getServiceApi().goods(ParamUtil.getParam(dataBean)).execute();
            ResponseResult result = response.body();
            return result;
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseResult.fail(e.getMessage());
        }
    }
}
